/**
 * 旅游景点信息JS
 * @author Assassin
 */
$(document).ready(function () {
    $('#uploadPictureLink').on('click', function () {
        $('#pictureFile').click();
    });
    $('#pictureImg').on('click', function () {
        $('#pictureFile').click();
    });
});

// 执行添加旅游景点信息
function excuteAddTouristInfo() {
    var title = $.trim($('#title').val());
    if (shiro.util.isEmpty(title)) {
        layer.tips('旅游景点标题不能为空', '#title');
        return false;
    }
    var price = $.trim($('#price').val());
    if (shiro.util.isEmpty(price)) {
        layer.tips('旅游景点价格不能为空', '#price');
        return false;
    }
    //景点优惠价格
    var salePrice = $.trim($('#salePrice').val());
    //
    var ticketNumber = $.trim($('#ticketNumber').val());
    if (shiro.util.isEmpty(ticketNumber)) {
        layer.tips('门票数量不能为空', '#desc');
        return false;
    }
    var desc = $.trim($('#desc').val());
    if (shiro.util.isEmpty(desc)) {
        layer.tips('旅游景点简介不能为空', '#desc');
        return false;
    }
    var feature = $.trim($('#feature').val());
    if (shiro.util.isEmpty(feature)) {
        layer.tips('旅游景点特征不能为空', '#feature');
        return false;
    }
    var address = $.trim($('#address').val());
    if (shiro.util.isEmpty(address)) {
        layer.tips('旅游景点位置不能为空', '#address');
        return false;
    }
    var lng = $.trim($('#lng').val());
    if (shiro.util.isEmpty(lng)) {
        layer.tips('旅游景点经度不能为空', '#lng');
        return false;
    }
    var lat = $.trim($('#lat').val());
    if (shiro.util.isEmpty(lat)) {
        layer.tips('旅游景点纬度不能为空', '#lat');
        return false;
    }
    var content = CKEDITOR.instances.content_editor.getData();
    if (shiro.util.isEmpty(content)) {
        layer.msg('旅游景点内容不能为空', {icon: 5, time: 1000});
        return false;
    }
    var descPhotos = $('#descPhotos').val();
    if (shiro.util.isEmpty(descPhotos)) {
        layer.msg('缩略图片不能为空', {icon: 5, time: 1000});
        return false;
    }
    //旅游星级
    var level = $('#level').val();
    // 提交信息
    shiro.ajax({
        url: 'tourist/executeAddTourist',
        data: {
            'title': title,
            'level': level,
            'price': price,
            'salePrice': salePrice,
            'ticketNumber': ticketNumber,
            'feature': feature,
            'address': address,
            'lng': lng,
            'lat': lat,
            "content": content,
            'desc': desc,
            "thumbnail": descPhotos
        },
        success: function (data) {
            if (data.result == 0) {
                layer.msg(data.message, {icon: 1, time: 1000}, function () {
                    window.location.href = shiro.baseUrl + "tourist/list";
                });
            } else {
                layer.msg(data.message, {icon: 5, time: 1000});
                $('#title').val('');
            }
        }
    });
    return false;
}

// 执行修改旅游景点信息
function excuteEditTouristInfo() {
    var title = $.trim($('#title').val());
    if (shiro.util.isEmpty(title)) {
        layer.tips('旅游景点标题不能为空', '#title');
        return false;
    }
    var price = $.trim($('#price').val());
    if (shiro.util.isEmpty(price)) {
        layer.tips('旅游景点价格不能为空', '#price');
        return false;
    }
    //景点优惠价格
    var salePrice = $.trim($('#salePrice').val());
    //
    var ticketNumber = $.trim($('#ticketNumber').val());
    if (shiro.util.isEmpty(ticketNumber)) {
        layer.tips('门票数量不能为空', '#ticketNumber');
        return false;
    }
    var desc = $.trim($('#desc').val());
    if (shiro.util.isEmpty(desc)) {
        layer.tips('旅游景点简介不能为空', '#desc');
        return false;
    }
    var feature = $.trim($('#feature').val());
    if (shiro.util.isEmpty(feature)) {
        layer.tips('旅游景点特征不能为空', '#feature');
        return false;
    }
    var address = $.trim($('#address').val());
    if (shiro.util.isEmpty(address)) {
        layer.tips('旅游景点位置不能为空', '#address');
        return false;
    }
    var lng = $.trim($('#lng').val());
    if (shiro.util.isEmpty(lng)) {
        layer.tips('旅游景点经度不能为空', '#lng');
        return false;
    }
    var lat = $.trim($('#lat').val());
    if (shiro.util.isEmpty(lat)) {
        layer.tips('旅游景点纬度不能为空', '#lat');
        return false;
    }
    var content = CKEDITOR.instances.content_editor.getData();
    if (shiro.util.isEmpty(content)) {
        layer.msg('旅游景点内容不能为空', {icon: 5, time: 1000});
        return false;
    }
    var thumbnail = $('#thumbnailUrls').val();
    if (shiro.util.isEmpty(thumbnail)) {
        layer.msg('缩略图片不能为空', {icon: 5, time: 1000});
        return false;
    }
    var touristId = $('#touristId').val();

    //旅游星级
    var level = $('#level').val();
    // 提交信息
    shiro.ajax({
        url: 'tourist/executeEditTourist',
        data: {
            'touristId': touristId,
            'title': title,
            'level': level,
            'price': price,
            'salePrice': salePrice,
            'ticketNumber': ticketNumber,
            'feature': feature,
            'address': address,
            'lng': lng,
            'lat': lat,
            "content": content,
            'desc': desc,
            "thumbnail": thumbnail
        },
        success: function (data) {
            if (data.result == 0) {
                layer.msg(data.message, {icon: 1, time: 1000}, function () {
                    window.location.href = shiro.baseUrl + "tourist/list";
                });
            } else {
                layer.msg(data.message, {icon: 5, time: 1000});
                $('#title').val('');
            }
        }
    });
    return false;
}

// 删除旅游景点
function deleteTourist(touristId) {
    //prompt层
    layer.prompt({title: '请说明删除理由', formType: 2}, function (text, index) {
        layer.close(index);
        // 提交删除
        shiro.ajax({
            url: 'tourist/delete',
            data: {"touristId": touristId, "delDesc": text},
            success: function (data) {
                if (data.result == 0) {
                    layer.msg(data.message, {icon: 1, time: 1000}, function () {
                        window.location.href = shiro.baseUrl + "tourist/list";
                    });
                } else {
                    layer.msg(data.message, {icon: 5, time: 1000});
                }
            }
        });
    });
}
    // 禁用游景点
    function disableTourist(touristId) {
        //prompt层
        layer.prompt({title: '请说明禁用理由', formType: 2}, function (text, index) {
            layer.close(index);
            // 提交删除
            shiro.ajax({
                url: 'tourist/disable',
                data: {"touristId": touristId, "disableDesc": text},
                success: function (data) {
                    if (data.result == 0) {
                        layer.msg(data.message, {icon: 1, time: 1000}, function () {
                            window.location.href = shiro.baseUrl + "tourist/list";
                        });
                    } else {
                        layer.msg(data.message, {icon: 5, time: 1000});
                    }
                }
            });
        });
    }
        // 启用旅游景点
        function startUsing(touristId) {
            layer.msg('确定启用该旅游项目？', {
                time: 0,
                btn: ['确定', '取消'],
                yes: function (index) {
                    layer.close(index);
                    shiro.ajax({
                        url: 'tourist/startUsing',
                        data: {"touristId": touristId},
                        success: function (data) {
                            if (data.result == 0) {
                                layer.msg(data.message, {icon: 1, time: 1000}, function () {
                                    window.location.href = shiro.baseUrl + "tourist/list";
                                });
                            } else {
                                layer.msg(data.message, {icon: 5, time: 1000});
                            }
                        }
                    });
                }
            });
        }


// 批量删除旅游景点
    function batchDeleteTourists() {
        var touristIdArray = shiro.form.getCheckBoxSelectValues('touristIdCheckBox');
        if (touristIdArray.length == 0) {
            layer.msg('请选择要操作的数据行', {icon: 5, time: 1000});
        } else {
            layer.msg('确定删除选中的旅游景点？', {
                time: 0,
                btn: ['确定', '取消'],
                yes: function (index) {
                    layer.close(index);
                    var touristIds = touristIdArray.join(',');
                    // 提交删除
                    shiro.ajax({
                        url: 'tourist/batchDelete',
                        data: {"touristIds": touristIds},
                        success: function (data) {
                            if (data.result == 0) {
                                layer.msg(data.message, {icon: 1, time: 1000}, function () {
                                    window.location.href = shiro.baseUrl + "tourist/list";
                                });
                            } else {
                                layer.msg(data.message, {icon: 5, time: 1000});
                            }
                        }
                    });
                }
            });
        }
    }
